package com.wty.example.automic;

import com.wty.annotations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author wangtengyu
 * @Create 2018-05-16-8:34
 */
@Slf4j
@ThreadSafe
public class AtomicExample4 {
    private static AtomicReference<Integer> count=new AtomicReference<Integer>(0);

    public static void main(String[] args) {
        count.compareAndSet(0,3);//更改为3
        count.compareAndSet(1,5);//不变化
        count.compareAndSet(2,4);//不变化
        count.compareAndSet(3,5);//变为5
        count.compareAndSet(5,8);//变为8
        System.out.println(count);
    }
}
